#include "threadtest.h"
#include "ui_threadtest.h"

ThreadTest::ThreadTest(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ThreadTest)
{
    ui->setupUi(this);
    connect(threadA, SIGNAL(sendSignal(QString)), this, SLOT(showThreadMessage(QString)));
    threadA->setMessage("A");
    connect(threadB, SIGNAL(sendSignal(QString)), this, SLOT(showThreadMessage(QString)));
    threadB->setMessage("B");
}

ThreadTest::~ThreadTest()
{
    delete ui;
}

void ThreadTest::showThreadMessage(QString message)
{
    QString showMessage = message;
//    showMessage.append("/n");
    ui->textBrowser->append(showMessage);
}

void ThreadTest::on_pushButton_clicked()
{
   if (!threadA->isRunning())
   {
       threadA->start();
       ui->pushButton->setText("stopA");
   }
   else
   {
       threadA->stop();
       ui->pushButton->setText("startA");
   }
}

void ThreadTest::on_pushButton_2_clicked()
{
    if (!threadB->isRunning())
    {
        threadB->start();
        ui->pushButton_2->setText("stopB");
    }
    else
    {
        threadB->stop();
        ui->pushButton_2->setText("startB");
    }

}

void ThreadTest::on_pushButton_3_clicked()
{
    ui->textBrowser->clear();
}
